package com.bj.dz.service.impl;

import com.bj.dz.entity.WaterfactoryDataformat;
import com.bj.dz.mapper.WaterfactoryDataformatMapper;
import com.bj.dz.service.WaterfactoryDataformatService;
import com.bj.dz.util.Constants;
import com.bj.dz.util.EmptyUtils;
import com.bj.dz.util.Page;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class WaterfactoryDataformatServiceImpl implements WaterfactoryDataformatService {

    @Resource
    private WaterfactoryDataformatMapper waterfactoryDataformatMapper;

    public WaterfactoryDataformat getWaterfactoryDataformatById(Integer id){
        return waterfactoryDataformatMapper.getWaterfactoryDataformatById(id);
    }

    public List<WaterfactoryDataformat>	getWaterfactoryDataformatListByMap(Map<String,Object> param){
        return waterfactoryDataformatMapper.getWaterfactoryDataformatListByMap(param);
    }

    public Integer getWaterfactoryDataformatCountByMap(Map<String,Object> param){
        return waterfactoryDataformatMapper.getWaterfactoryDataformatCountByMap(param);
    }

    @Transactional
    public boolean addWaterfactoryDataformat(WaterfactoryDataformat waterfactoryDataformat){
            return waterfactoryDataformatMapper.insertWaterfactoryDataformat(waterfactoryDataformat)>0?true:false;
    }

    @Transactional
    public boolean modifyWaterfactoryDataformat(WaterfactoryDataformat waterfactoryDataformat){
        return waterfactoryDataformatMapper.updateWaterfactoryDataformat(waterfactoryDataformat)>0?true:false;
    }

    @Transactional
    public boolean deleteWaterfactoryDataformatById(Integer id){
        return waterfactoryDataformatMapper.deleteWaterfactoryDataformatById(id)>0?true:false;
    }

    public Page<WaterfactoryDataformat> queryWaterfactoryDataformatPageByMap(Map<String,Object> param, Integer pageNo, Integer pageSize){
        Integer total = waterfactoryDataformatMapper.getWaterfactoryDataformatCountByMap(param);
        pageNo = EmptyUtils.isEmpty(pageNo) ? Constants.DEFAULT_PAGE_NO : pageNo;
        pageSize = EmptyUtils.isEmpty(pageSize) ? Constants.DEFAULT_PAGE_SIZE : pageSize;
        Page page = new Page(pageNo, pageSize, total);
        param.put("beginPos", page.getBeginPos());
        param.put("pageSize", page.getPageSize());
        List<WaterfactoryDataformat> waterfactoryDataformatList = waterfactoryDataformatMapper.getWaterfactoryDataformatListByMap(param);
        page.setRows(waterfactoryDataformatList);
        return page;
    }

}
